package com.ai.sort;
/**
 * @Author jia
 * @Description //冒泡排序
**/
public class Bubbling {

    public static void bubbleSort(int arr[]){
        int n = arr.length;
        boolean swapped;

        for (int i = 0; i < n-1; i++) {
            swapped = false;
            for (int j = 0; j < n-i-1; j++) {
                if (arr[j] > arr[j+1]) {
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    swapped = true;
                }
            }
            if (!swapped) {
                break;
            }
        }
    }

    public static void main(String[] args) {
        int arr[] ={64,34,25,12,22,11,90};
        bubbleSort(arr);
        System.out.println("排序后的数组：");
        for(int i : arr){
            System.out.println(i+" ");
        }
    }
}
